package com.yaorange.jk.service.impl;

import com.yaorange.jk.dao.BaseDao;
import com.yaorange.jk.entity.Module;
import com.yaorange.jk.service.ModuleService;
import com.yaorange.jk.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @author coach tam
 * @date 2017/11/1
 */
@Service("moduleService")
@Transactional
public class ModuleServiceImpl implements ModuleService {


    @Autowired
    private BaseDao<Module,String> moduleDao;

    @Override
    @Transactional(readOnly = true)
    public Pagination findPage(int pageNo, int pageSize) {
        return moduleDao.pageByHql("from Module",pageNo,pageSize);
    }


    @Override
    public List<Module> findAll() {
        return moduleDao.getListByHQL("from Module");
    }

    @Override
    public void save(Module module) {



        moduleDao.save(module);
    }

    @Override
    public Module findById(String id) {
        return moduleDao.get(Module.class,id);
    }

    @Override
    public void update(Module model) {
        //根据主键查询出老数据
        Module oldModule = moduleDao.get(Module.class,model.getId());
        moduleDao.evcit(oldModule);

        model.setCreateTime(oldModule.getCreateTime());
        model.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        //TODO  记录更新人
//        model.setUpdateBy();
        moduleDao.update(model);
    }

    @Override
    public void deleteByIds(String[] ids) {
        for (String id :ids)
        {
            moduleDao.deleteById(Module.class,id);
        }
    }
}
